import Vue from 'vue'
import VueRouter from 'vue-router'
import api from './api/index'
Vue.use(VueRouter)

const routes = [
    {
        path: "/",
        redirect: "/loading",
    },
	// {
	//     path: "/wrapper",
	//     component: () =>
	//       import(/* webpackChunkName: "about" */ "./components/Wrapper"),
	//     children: [{
	//         path: "/index",
	//         name: "政策",
	//         component: () => import("./views/index/index.vue"),
	//         meta: { isShowTabbar: true,isLogin:true,keepAlive:true}
	//       }, {
	//         path: "/member",
	//         name: "我的",
	//         component: () =>
	//         import(/* webpackChunkName: "manage" */ "./views/member/index.vue"),
	//         meta: { isShowTabbar: true,isLogin:true,keepAlive:true}
	//       },
	//     ]
	// },
	{
	    path: "/index",
	    name: "苍南县数字创业服务平台",
	    component: () => import("./views/index/index.vue"),
	    meta: { isShowTabbar: true,isLogin:true,keepAlive:true}
	},
	{
	    path: "/member",
	    name: "我的",
	    component: () =>
	    import(/* webpackChunkName: "manage" */ "./views/member/index.vue"),
	    meta: { isShowTabbar: true,isLogin:true,keepAlive:true}
	},
	{
		path: "/index/detail",
		name: '政策详情',
		meta: {isShowTabbar: false,isLogin:true,keepAlive:false},
		component: () => import("./views/index/detail.vue"),
	},
	{
	    path: "/member/question",
	    name: '常见问答',
	    meta: {isShowTabbar:false,isLogin:false,keepAlive:false},
	    component: () => import("./views/member/question.vue"),
	},
	{
	    path: "/member/feedback",
	    name: '帮助与反馈',
	    meta: {isShowTabbar:false,isLogin:false,keepAlive:false},
	    component: () => import("./views/member/feedback.vue"),
	},
	{
	    path: "/member/set",
	    name: '设置',
	    meta: {isShowTabbar:false,isLogin:true,keepAlive:false},
	    component: () => import("./views/member/set.vue"),
	},
	{
	    path: "/member/userInfo",
	    name: '个人信息',
	    meta: {isShowTabbar:false,isLogin:true,keepAlive:false},
	    component: () => import("./views/member/userInfo.vue"),
	},
	{
	    path: "/member/editUserInfoView",
	    name: '所需个人信息预览',
	    meta: {isShowTabbar:false,isLogin:false,keepAlive:false},
	    component: () => import("./views/member/editUserInfoView.vue"),
	},
	{
	    path: "/member/editUserInfo",
	    name: '编辑',
	    meta: {isShowTabbar:false,isLogin:true,keepAlive:false},
	    component: () => import("./views/member/editUserInfo.vue"),
	},
	{
		path: "/match",
		name: '政策匹配',
		meta: {isShowTabbar: false,isLogin:true,keepAlive:false},
		component: () => import("./views/index/match.vue"),
	},
	{
		path: "/applyResult",
		name: '我的申请',
		meta: {isShowTabbar: false,isLogin:true,keepAlive:false},
		component: () => import("./views/index/applyResult.vue"),
	},
	{
		path: "/searchResult",
		name: '搜索结果',
		meta: {isShowTabbar: false,isLogin:true,keepAlive:false},
		component: () => import("./views/index/searchResult.vue"),
	},
	{
		path: "/matchResult",
		name: '匹配结果',
		meta: {isShowTabbar: false,isLogin:true,keepAlive:false},
		component: () => import("./views/index/matchResult.vue"),
	},
	{
		path: "/matchFail",
		name: '匹配失败',
		meta: {isShowTabbar: false,isLogin:true,keepAlive:false},
		component: () => import("./views/index/matchFail.vue"),
	},
	{
		path: "/collect",
		name: '我的收藏',
		meta: {isShowTabbar: false,isLogin:true,keepAlive:true},
		component: () => import("./views/member/collect.vue"),
	},
    {
        path: "/login",
        name: '登录',
        meta: {isShowTabbar: false,isLogin:false},
        component: () => import("./views/login/index.vue"),
    },
    {
        path: "/loading",
        name: '苍南县数字创业服务平台',
        meta: {isShowTabbar:false,isLogin:false},
        component: () => import("./views/loading.vue"),
    },
];

const router = new VueRouter({
    routes,
    scrollBehavior (to, from, savedPosition) {
		const _this = new Vue()
        // return 期望滚动到哪个的位置
		// console.log('scrollBehavior')
		// console.log('to, from',to, from)
		if(to.path=='/index'){
			_this.bus.$emit('scrollToTop')
			
		}
		if(to.path == '/searchResult'){
			_this.bus.$emit('scrollToTop4Result')
		}
		// if (savedPosition) {
		//     return savedPosition
		// } else {
		//     return { x: 0, y: 0 } //期望滚动到哪个的位置
		// }
		
        
    }
})
// 路由守卫
router.beforeEach((to, from, next) => {
  // if(!to.meta.isShowTabbar) {
  //   document.title = to.name;
  // }
	document.title = to.name;
	
	next()
  // if(to.matched.some(res=>res.meta.isLogin)){//判断是否需要登录
  //     if (localStorage.getItem(process.env.VUE_APP_TOKEN_NAME)) {
  //         api.vLogin().then(result => {
  //             next();
  //         });
  //     }else{
  //         next({
  //             path:"/login",
  //             query:{
  //                 redirect:to.fullPath
  //             }
  //         });
  //     }

  // }else{
  //     next()
  // }
});
export default router
